{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Sigmoid函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def sigmoid(t):\n",
    "    return 1 / (1 + np.exp(-t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAH8RJREFUeJzt3Xt83HWd7/HXJ/dekl6T3i/UFmi5YyggKpVCLaiU9YFYVtcLal324OXselbUfbBe9pzj6jm7Z32IuhVZELmqKBWrLVQQFIGmFwptKA1t2qSXJG1C0zbNZWY+54+ZwhAmzaSZyW/ml/fz8Ugzv9/vOzOf/ObXd375zm++X3N3REQkXAqCLkBERDJP4S4iEkIKdxGREFK4i4iEkMJdRCSEFO4iIiGkcBcRCSGFu4hICCncRURCqCioJ544caLPnj07qKcXEclLGzZsOOjulf21CyzcZ8+eTU1NTVBPLyKSl8xsdzrt1C0jIhJCCncRkRBSuIuIhJDCXUQkhBTuIiIh1G+4m9mdZtZsZi/1sd3M7HtmVmdmW8zswsyXKSIiA5HOmftdwNKTbL8amJf4WgH8cPBliYjIYPR7nbu7P2Vms0/SZBnwU4/P1/esmY01synuvj9DNYpISMViTlckRmdPlM5IlEjU6YnGiMacnqgTicWIxJzIidtRT2yLt4nEnJg77uA4sRjxZcAT62Oeap0T8zeWHX+jXdLMo8nTkL5pfcp1b237pklMkxovnj+J82aMHezuO6l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4j/hv4+eQGidB4gvhk3RCfvLuvvwQG60rgZXdvTLXRzEaZWfmJ28TfVHwpVdtM6dXP+Vd9PF86E59nuq6lwJeBa929o482Q7W/cnLi90Sf/k+AWnf/tz7aTD7R929mC4n/Pz6U5brSeV1WAR9LXDVzCXD4RHfEEOjzr+cg9lcvycdRX1m0BlhiZuMS3ahLEutO3VC8g3wqX8RDqRHoApqANUnbvkb8SoftwNVJ61cDUxO35xAP/Trg50Bpluq8C/jbXuumAquT6ngh8bWVePdEtvfdPcCLwJbEgTWld12J5WuIX43x6hDVVUe8X3Fz4utHvesayv2V6ucHvkn8lw9AWeLYqUscS3OGYB+9k/if41uS9tM1wN+eOM6AWxL75gXib0y/YwjqSvm69KrLgNsT+/NFkq5yy3JtI4mH9ZikdYHsL+K/YPYDPYn8+hTx92nWATsS38cn2lYDdyTd96bEsVYHfHKwtegTqiIiIZSP3TIiItIPhbuISAgp3EVEQkjhLiISQgp3EZEQUriLiISQwl1EJIQU7iIiIfT/AfDvTn1iOeRyAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2f385748400>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = np.linspace(-10,10,500)\n",
    "y = sigmoid(x)\n",
    "\n",
    "plt.plot(x, y)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### $\\hat p^{(i)} = \\sigma(X_b^{(i)}\\theta) = \\frac{1}{1+e^{-X_b^{(i)}\\theta}}$\n",
    "#### $J(\\theta)=-\\frac{1}{m}\\sum_{i=1}^{m}[y^{(i)}log(\\hat p^{(i)}) + (1-y^{(i)})log(1-\\hat p^{(i)})]$\n",
    "没有公式解, 只能使用梯度下降法求解"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 逻辑回归梯度下降法公式推导"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### ${\\sigma(t)}'= (1+e^{-t})^{-2}\\cdot e^{-t}$\n",
    "#### ${(log\\  \\sigma(t))}'=\\frac{1}{\\sigma(t)}\\cdot{\\sigma(t)}'=\\frac{1}{\\sigma(t)}\\cdot(1+e^{-t})^{-2}\\cdot e^{-t} = (1+e^{-t})^{-1}\\cdot e^{-t}=1-\\frac{1}{1+e^{-t}}=1-\\sigma(t)$\n",
    "### $\\frac{d(y^{(i)}log\\ \\sigma(X_b^{(i)}\\theta))}{d\\theta_j}=y^{(i)}(1-\\sigma(X_b^{(i)}\\theta))\\cdot X_j^{(i)}$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "------------------------------------------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### ${(log(1 - \\sigma(t)))}'=-\\frac{1}{1+e^{-t}}=-\\sigma(t)$\n",
    "### $\\frac{d\\ [\\ (1-y^{(i)})\\ \\cdot \\ log(1-\\sigma(X_b^{(i)}\\theta))\\ ]}{d\\theta_j}=(1-y^{(i)})\\cdot(-\\sigma(X_b^{(i)}\\theta))\\cdot X_j^{(i)}$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---------------------------------------------------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### $\\frac{d\\ J(\\theta)}{d\\ \\theta_j}=\\frac{1}{m}\\sum_{i=1}^m (\\sigma(X_b^{(i)}\\theta)-y^{(i)})X_j^{(i)}=\\frac{1}{m}\\sum_{i=1}^m ({\\hat y}^{(i)} -y^{(i)})X_j^{(i)}$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---------------------------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### $J(\\theta)=MSE(y, \\hat y)$  \n",
    "####    $\\nabla J(\\theta)=\\begin{pmatrix} \n",
    "    \\frac{\\partial J}{\\partial \\theta_0} \n",
    "    \\\\ \\frac{\\partial J}{\\partial \\theta_1}\n",
    "    \\\\ \\ldots\n",
    "    \\\\ \\frac{\\partial J}{\\partial \\theta_n}\n",
    "    \\end{pmatrix} = \\frac{2}{m} \n",
    "    \\begin{pmatrix}\\\\ \n",
    "    \\sum_{i=1}^{m}(X_b^{(i)}\\theta - y^{(i)})\n",
    "    \\\\ \\sum_{i=1}^{m}(X_b^{(i)}\\theta - y^{(i)}) X_1^{(i)}\n",
    "    \\\\ \\sum_{i=1}^{m}(X_b^{(i)}\\theta - y^{(i)}) X_2^{(i)}\n",
    "    \\\\ \\ldots\n",
    "    \\\\ \\sum_{i=1}^{m}(X_b^{(i)}\\theta - y^{(i)}) X_n^{(i)}\n",
    "    \\end{pmatrix}=\\frac{2}{m} \\cdot X_b^T \\cdot (X_b\\theta - y) \\tag{线性回归}$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "------------------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### $\\nabla J(\\theta)=\\begin{pmatrix} \n",
    "    \\frac{\\partial J}{\\partial \\theta_0} \n",
    "    \\\\ \\frac{\\partial J}{\\partial \\theta_1}\n",
    "    \\\\ \\ldots\n",
    "    \\\\ \\frac{\\partial J}{\\partial \\theta_n}\n",
    "    \\end{pmatrix} = \\frac{1}{m} \n",
    "    \\begin{pmatrix}\\\\ \n",
    "    \\sum_{i=1}^{m}(\\sigma(X_b^{(i)}\\theta) - y^{(i)})\n",
    "    \\\\ \\sum_{i=1}^{m}(\\sigma(X_b^{(i)}\\theta) - y^{(i)}) X_1^{(i)}\n",
    "    \\\\ \\sum_{i=1}^{m}(\\sigma(X_b^{(i)}\\theta)- y^{(i)}) X_2^{(i)}\n",
    "    \\\\ \\ldots\n",
    "    \\\\ \\sum_{i=1}^{m}(\\sigma(X_b^{(i)}\\theta) - y^{(i)}) X_n^{(i)}\n",
    "    \\end{pmatrix}=\\frac{1}{m} \\cdot X_b^T \\cdot (\\sigma(X_b\\theta) - y)\\tag{逻辑回归}$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 使用自己封装的逻辑回归模型实现逻辑回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn import datasets\n",
    "\n",
    "iris = datasets.load_iris()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(100, 2) (100,)\n"
     ]
    }
   ],
   "source": [
    "X = iris.data\n",
    "y = iris.target\n",
    "\n",
    "X = X[y<2, :2]  # y<2筛选出2类, :2留2个特征, 方便后面可视化\n",
    "y = y[y<2]\n",
    "print(X.shape, y.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAF1hJREFUeJzt3W+MXFd5x/Hv45kUMDREIqsSxX9WFYi2oBDiVQhNhUJsqhAs8wKqplpKg1q5eEMJLRV/GilVLSFUIVGgYKMlqEpqt4QGaANKaZsAhb4g1TokgWBaBWonTmizSUrS1G0q209f3Lt4d3Z25p6ZOTPnnPl9pKuduXN89zn3Xj++Pve5Z8zdERGRsmyadAAiIjJ6Su4iIgVSchcRKZCSu4hIgZTcRUQKpOQuIlIgJXcRkQIpuYuIFEjJXUSkQO2mDc2sBSwBj7j77o7PrgU+DDxSr/qEu9/Ua3vnn3++z87OBgUrIjLtjhw58ri7z/Rr1zi5A9cDR4FzN/j8Vnd/Z9ONzc7OsrS0FPDrRU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ISqiEiBpnJYRkSkdEruIiIFUnIXESmQkruISIGU3EVECqTkLiJSICV3EZECKbmLiBTo/wF71ENhAg0WoQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2f3893d3400>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X[y==0,0], X[y==0,1], color='r')\n",
    "plt.scatter(X[y==1,0], X[y==1,1], color='b')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=666)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "ename": "ImportError",
     "evalue": "cannot import name 'LogisticRegression'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mImportError\u001b[0m                               Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-9-b08e7b7757fd>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mc26_LogisticRegression\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mLogisticRegression\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[0mlog_reg\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mLogisticRegression\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[0mlog_reg\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX_train\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my_train\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mImportError\u001b[0m: cannot import name 'LogisticRegression'"
     ]
    }
   ],
   "source": [
    "from c26_LogisticRegression import LogisticRegression\n",
    "\n",
    "log_reg = LogisticRegression()\n",
    "log_reg.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
